﻿


/*-------------------------------------------------------------------------
 * 版权所有：	黑客马拉松
 * 作者：		罗毅
 * 联系方式：	whluoyi@gmail.com
 * 创建时间：	2016/10/29 11:23:16
 * 版本号：		v1.0
 * 用途描述：	SuperMarieApi业务对象
 *  -------------------------------------------------------------------------*/

namespace SuperMarieApi.App.Controllers.Biz
{
    using System;
    using System.Collections.Generic;
    using System.Data;

    using SuperMarieApi.App.Controllers.Entity;
    using SuperMarieApi.App.Controllers.Framework.DataAccess;
    using SuperMarieApi.App.Controllers.Tool.Extensions;

    public class MyImgBiz
    {
        /// <summary>
        /// 获取MyImg列表
        /// </summary>
        /// <returns></returns>
        public static List<MyImgEntity> GetMyImgList()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyImgList");
            List<MyImgEntity> lists = cmd.ExecuteEntityList<MyImgEntity>();
            return lists;
        }

        /// <summary>
        /// 获取MyImg列表
        /// </summary>
        /// <returns></returns>
        public static DataTable GetMyImgData()
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyImgList");
            return cmd.ExecuteDataSet().Tables[0];
        }

        /// <summary>
        /// 获取MyImg详情
        /// </summary>
        /// <returns></returns>
        public static MyImgEntity GetMyImgObj(int MyImg_ID)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Get-MyImg");
            cmd.SetParameterValue("@MyImg_ID", MyImg_ID);
            MyImgEntity obj = cmd.ExecuteEntity<MyImgEntity>();
            return obj;
        }

        /// <summary>
        /// 更新MyImg详情
        /// </summary>
        /// <returns></returns>
        public static int SetMyImgObj(MyImgEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Set-MyImg");
            cmd.SetParameterValue("@MyImg_ID", obj.MyImg_ID);
            cmd.SetParameterValue("@FileUrl", obj.FileUrl);
            cmd.SetParameterValue("@FilePath", obj.FilePath);
            cmd.SetParameterValue("@Filebase64", obj.Filebase64);
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            int i = cmd.ExecuteNonQuery();
            return i;
        }

        /// <summary>
        /// 插入MyImg详情
        /// </summary>
        /// <returns></returns>
        public static int InsertMyImgObj(MyImgEntity obj)
        {
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Insert-MyImg");
            cmd.SetParameterValue("@FileUrl", obj.FileUrl);
            cmd.SetParameterValue("@FilePath", obj.FilePath);
            cmd.SetParameterValue("@Filebase64", "");
            cmd.SetParameterValue("@AddTime", obj.AddTime);
            object identity = cmd.ExecuteScalar();
            if (identity == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(identity);
            }
        }

        /// <summary>
        /// 分页MyImg数据列表
        /// </summary>
        /// <returns></returns>
        public static DataSet PageMyImgList(int pageSize, int pageIndex, string strWhere, string sortField = "MyImg_ID", string sortOrder = "DESC")
        {
            if (!strWhere.SqlFilter_List())
            {
                return null;
            }
            string pagesort = "";
            string pagewhere = "";
            string pageindexsize = "";
            if (!string.IsNullOrEmpty(sortField.Trim()))
            {
                pagesort = "ORDER BY " + sortField + " " + sortOrder;
            }
            else
            {
                pagesort = "ORDER BY T.MyImg_ID " + sortOrder;
            }
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                pagewhere = " WHERE " + strWhere;
            }
            pageindexsize = " WHERE TT.Row between " + ((pageIndex - 1) * pageSize + 1) + " and " + (pageIndex * pageSize);
            DataCommand cmd = DataCommandManager.GetDataCommand("SuperMarieApi.Page-MyImg");
            cmd.SetParameterValue("@pagesort", pagesort);
            cmd.SetParameterValue("@pagewhere", pagewhere);
            cmd.SetParameterValue("@pageindexsize", pageindexsize);
            return cmd.ExecuteDataSet();
        }
    }
}